<?php

namespace App\Model;

class RoomTag extends BaseModel
{
    protected $table = 'room_tag';
    private $fields = ['id', 'room_type_id', 'tag_name', 'tag_color', 'status'];


    public function getTagByType($type)
    {
        $query = new self();
        return $query->where('room_type_id', '=', $type)->where('status', '=', 1)->select($this->fields)->get();
    }

    public function delTag($data)
    {
        return curl_request(getKkaudioApiUrl() . '/inner/room/tag/update', $data, 'urlencoded', 'GET');
    }

    public function getTagById($id)
    {
        $query = new self();
        return $query->where('id', '=', $id)->where('status', '=', 1)->select($this->fields)->first();
    }

    public function createTag($data)
    {

        $count = $this->getTagByType($data['room_type_id']);

        if (count(json_decode($count, true)) > 8) {
            $res['code'] = 100006;
            $res['msg'] = '最多上传8个标签';
            return $res;
        }
        return curl_request(getKkaudioApiUrl() . '/inner/room/tag/create', $data, 'urlencoded', 'GET');
    }

    /**
     * 靓号更新操作
     */
    public function liangTag($data)
    {
        $d['room_id'] = $data['room_id']; //房间id
        $d['room_liang_type'] = intval($data['room_liang_type']); //1显示0隐藏
        return curl_request(getKkaudioApiUrl() . '/inner/room/update', $d, 'urlencoded', 'GET');
    }

    public function heart($data)
    {
        $d['room_id'] = $data['room_id'];
        $d['heart'] = intval($data['heart']);
        return curl_request(getKkaudioApiUrl() . '/inner/room/update', $d, 'urlencoded', 'GET');
    }


}
